﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>"  %>
<%@ Import Namespace="UncleBobWebService.Models" %>
<%@ Import Namespace="UncleBobApplicantWebService.Controllers" %>

<!DOCTYPE html>

<html>
<head id="EditQuestion" runat="server">
    <title>Staffing Expert Edit Question</title>
    <link href="/Theme/UncleBobTheme.css" rel="Stylesheet" />
</head>

<body>
<h2>Edit Question</h2>
    <div class="body">

        <!-- Begin Form 
                                  Method        Route Config Name
        -->
        <% using (Html.BeginForm("FormAction", "EditQuestion", FormMethod.Post)) {%>
            <% bool mQtype = false;
               string txt;
               int ID;             
               HtmlTextArea txtArea;
               HtmlInputCheckBox chkBox;
               MultipleChoiceQuestion mQ = Model as MultipleChoiceQuestion;
               ExtendedQuestion eQ = Model as ExtendedQuestion; 
               
               if (mQ != null)
               {
                   mQtype = true;
               }
               else
               {
                   eQ = Model as ExtendedQuestion;                   
               }
               
                if (mQtype)
                         {
                             txt = mQ.Question;
                             ID = mQ.QuestionID;
                             Session.Add(SessionKeys.QUESTION, mQ);
                         }
                         else
                         {
                             txt = eQ.Question;
                             ID = eQ.QuestionID;
                             Session.Add(SessionKeys.QUESTION, eQ);
                         }

                         
                         txtArea = (HtmlTextArea)Page.FindControl("QuestionText");
                         txtArea.Value = txt;                         
                         %>
                               
            %>

            <div class="box">
                <div class="left-justify">
                Question
                     <div>                   
                        <textarea id= "QuestionText" name="question" style="resize: none;" rows="10" cols="72" runat="server"></textarea>                       
                     </div>                   
                     <div>
                     If your question is multiple choice please provide the required answers.                     
                     </div>
                     <br />
                    <div>
                    Answer 1
                         <div>
                          <% if (mQtype)
                               {
                                   if (((MultipleChoiceQuestion)mQ).PossibleAnswers.Count >= 1)
                                   {
                                       Answer a = ((MultipleChoiceQuestion)mQ).PossibleAnswers[0];
                                       txtArea = (HtmlTextArea)Page.FindControl("Answer1");
                                       txtArea.Value = a.TheAnswer;                                     
                                       chkBox = (HtmlInputCheckBox)Page.FindControl("AnswerCheckBox1");
                                       chkBox.Checked = a.IsCorrect;
                                   }
                               }                               
                                %>
                            <textarea id="Answer1" name="answer1" style="resize: none; width: 498px;" rows="2" cols="72" runat="server"></textarea>                                          
                             <input id="AnswerCheckBox1" type=checkbox name="answerCorrect1"  runat="server"/>Correct?                                                   
                         </div>
                    </div>
                    <div>
                    Answer 2
                         <div>
                         <% if (mQtype)
                               {
                                   if (((MultipleChoiceQuestion)mQ).PossibleAnswers.Count >= 2)
                                   {
                                       Answer a = ((MultipleChoiceQuestion)mQ).PossibleAnswers[1];
                                       txtArea = (HtmlTextArea)Page.FindControl("Answer2");
                                       txtArea.Value = a.TheAnswer;                                     
                                       chkBox = (HtmlInputCheckBox)Page.FindControl("AnswerCheckBox2");
                                       chkBox.Checked = a.IsCorrect;
                                   }
                               }
                                %>
                            <textarea  id="Answer2" name="answer2" style="resize: none; width: 498px;" rows="2" cols="72" runat="server"></textarea>              
                            <input  id="AnswerCheckBox2" type=checkbox name="answerCorrect2"  runat="server"/>Correct?                                                  
                         </div>              
                    </div>
                    <div>
                    Answer 3
                         <div>
                         <% if (mQtype)
                               {
                                   if (((MultipleChoiceQuestion)mQ).PossibleAnswers.Count >= 3)
                                   {
                                       Answer a = ((MultipleChoiceQuestion)mQ).PossibleAnswers[2];
                                       txtArea = (HtmlTextArea)Page.FindControl("Answer3");
                                       txtArea.Value = a.TheAnswer;                                     
                                       chkBox = (HtmlInputCheckBox)Page.FindControl("AnswerCheckBox3");
                                       chkBox.Checked = a.IsCorrect;
                                   }
                               }
                                %>
                            <textarea  id="Answer3" name="answer3" style="resize: none; width: 498px;" rows="2" cols="72" runat="server"></textarea>              
                            <input id="AnswerCheckBox3" type=checkbox name="answerCorrect3"  runat="server"/>Correct?                     
                         </div>              
                    </div>
                    <div>
                    Answer 4
                         <div>
                         <% if (mQtype)
                               {
                                   if (((MultipleChoiceQuestion)mQ).PossibleAnswers.Count >= 4)
                                   {
                                       Answer a = ((MultipleChoiceQuestion)mQ).PossibleAnswers[3];
                                       txtArea = (HtmlTextArea)Page.FindControl("Answer4");
                                       txtArea.Value = a.TheAnswer;                                     
                                       chkBox = (HtmlInputCheckBox)Page.FindControl("AnswerCheckBox4");
                                       chkBox.Checked = a.IsCorrect;
                                   }
                               }
                                %>
                            <textarea  id="Answer4" name="answer4" style="resize: none; width: 498px;" rows="2" cols="72" runat="server"></textarea>              
                            <input id="AnswerCheckBox4" type=checkbox name="answerCorrect4"  runat="server"/>Correct?                        
                         </div>              
                    </div>
                    <div>
                    Answer 5
                         <div>
                         <% if (mQtype)
                               {
                                   if (((MultipleChoiceQuestion)mQ).PossibleAnswers.Count >= 5)
                                   {
                                       Answer a = ((MultipleChoiceQuestion)mQ).PossibleAnswers[4];
                                       txtArea = (HtmlTextArea)Page.FindControl("Answer5");
                                       txtArea.Value = a.TheAnswer;                                     
                                       chkBox = (HtmlInputCheckBox)Page.FindControl("AnswerCheckBox5");
                                       chkBox.Checked = a.IsCorrect;
                                   }
                               }
                                %>
                            <textarea  id="Answer5" name="answer5" style="resize: none; width: 498px;" rows="2" cols="72" runat="server"></textarea>              
                            <input id="AnswerCheckBox5" type=checkbox name="answerCorrect5" runat="server" />Correct?                       
                         </div>              
                    </div>
                </div>
             </div>
           
        <!-- Buttons -->      
        <input class="button" type="submit" name="questionSubmit" value="Submit" />
        <input class="button" type="submit" name="questionCancel" value="Cancel" />
        <%}%>
    </div>
</body>
</html>
